package com.zhihui.client.alarm.service.impl;

import com.zhihui.client.alarm.common.Lay;
import com.zhihui.client.alarm.common.Msg;
import com.zhihui.client.alarm.dao.MonitorpointMapper;
import com.zhihui.client.alarm.entity.Monitorpoint;
import com.zhihui.client.alarm.service.MonitorpointService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 服务实现
 * @author zhihuian
 * @email 18037017565@163.com
 * @date 2018/10/29
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MonitorpointServiceImpl implements MonitorpointService {
    @Resource
    private MonitorpointMapper monitorpointMapper;

    @Override
    public Msg addMonitorpoint(Monitorpoint monitorpoint) {
        int i=  monitorpointMapper.insert(monitorpoint);
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("添加成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("添加失败");
        }
        return msg;
    }

    @Override
    public Msg updateMonitorpoint(Monitorpoint monitorpoint) {
        int i= monitorpointMapper.updateByParam(monitorpoint);
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("修改成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("修改失败");
        }
        return msg;
    }

    @Override
    public Msg delMonitorpoint(Monitorpoint monitorpoint) {
        int i=monitorpointMapper.del(monitorpoint.getMptid());
        Msg msg=new Msg();
        if (i>0){
            msg.setMsg("删除成功");
        }else{
            msg.setCode(-1);
            msg.setMsg("删除失败");
        }
        return msg;
    }

    @Override
    public Lay getMonitorpoints(Monitorpoint monitorpoint, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Monitorpoint> monitorpoints=monitorpointMapper.list(monitorpoint);
        PageInfo info=new PageInfo(monitorpoints);
        Lay lay=new Lay();
        lay.setPage(page);
        lay.setCount(info.getTotal());
        lay.setData(info.getList());
        return lay;
    }
}
